module.exports = app => {
  const Sequelize = app.Sequelize;

  const UserModel = app.model.define(
    'user',
    {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      name: {
        type: Sequelize.STRING,
      },
    },
    {
      tableName: 'student',
      timestamps: true,
      underscoredAll: true,
    }
  );

  UserModel.getData = () => {
    return new Promise((resolve, reject) => {
      const sql = 'SELECT * FROM student';
      app.model
        .query(sql)
        .spread(results => {
          resolve(results);
        })
        .catch(err => {
          reject(err);
        });
    });
  };

  return UserModel;
};
